#include <iostream>
#include <string>
using namespace std;
//工厂方法是针对每一种产品提供一个工厂类。通过不同的工厂实例来创建不同的产品实例
//在同一等级结构中，支持增加任意产品

class IUser
{
public:
	virtual void getUser() = 0;
	virtual void setUser() = 0;
};

class SqlUser :public IUser
{
public:
	void getUser() override
	{
		cout << "在Sql中返回user" << endl;
	}

	void setUser() override
	{
		cout << "在Sql中设置user" << endl;
	}
};

class AccessUser : public IUser
{
public:
	void getUser() override
	{
		cout << "在Access中返回user" << endl;
	}
	void setUser() override
	{
		cout << "在Access中设置user" << endl;
	}
};

class IFactory //抽象工厂
{
public:
	virtual IUser * createUser() = 0;
};

//sql工厂
class SqlFactory :public IFactory
{
public:

	IUser * createUser()override
	{
		return new SqlUser();
	}
};

//Access工厂
class AccessFactory :public IFactory
{
public:
	IUser * createUser()override
	{
		return new AccessUser();
	}
};

void main3()
{
	SqlFactory * sqlFactory = new SqlFactory();
	SqlUser * sqlUser = reinterpret_cast<SqlUser *>(sqlFactory->createUser());
	sqlUser->setUser();
	delete(sqlUser);
	delete(sqlFactory);

	system("pause");
}